#include <iostream>
#include <fstream>
#include <math.h>
#include <opencv2\opencv.hpp>

using namespace cv;
using namespace std;

#define SQUARE(v) ((v)*(v))
#define BGR2GRAY(b,g,r) (0.30f*r + 0.59f*g + 0.11f*b)
#define MHT_DIS(x1,y1,x2,y2) (abs((x1) - (x2)) + abs((y1) - (y2)))
#define P2P_DIS(p1,p2) MHT_DIS((p1).x,(p1).y,(p2).x,(p2).y)

struct BarVector{
    Point2f p1;
    Point2f p2;
    float module;
};

class Recognizer{
private:
    ofstream fstm;
    Mat srcImg;
private:
    void step(uchar* ptr, int &s, int &w, int &h, Point2f &p1, Point2f &p2, float &dis);
    void extendLine(Mat &sub, vector<BarVector> &vs, const int &lenLimit);
    void lineImage(Mat &image, vector<BarVector> &vs);
public:
    Recognizer();
    ~Recognizer();
    void setDataInfoPath(string path);
    float vectorCos(const BarVector &v1, const BarVector &v2);
    void recognize(Mat &image, vector<RotatedRect> &retRect);
	void imgSplit(Mat &image, vector<Mat> &subs);
	void train(Mat &image,bool vaild);
	bool predict(Mat &image);
    void showLineImage(Mat &image);
};
